<?php defined("MAIN_DIR") or die("No direct access");

$auto_id = UV::readInt($route->getPath(4));
if ($auto_id == "") {
	to("/$c_name/credits/");
}

$auto_res = mysql_query("select `A`.*,`B`.`city_id`,`B`.`link`,`B`.`name` as `bank_name` from `auto` as `A`,`bank` as `B` where `A`.`auto_id` = '$auto_id' and `A`.`bank_id` = `B`.`bank_id` limit 1");

if (mysql_num_rows($auto_res) == 0) {
	to("/$c_name/credits/");
}

$auto_row = mysql_fetch_array($auto_res);
$city_row = mysql_fetch_array(mysql_query("select * from `city` where `city_id` = '$auto_row[city_id]' limit 1"));
if ($_SESSION['city'] != $auto_row['city_id']) {
	to("/$city_row[path]/credits/auto/$auto_row[auto_id]");
}

$head_title = "Кредит ".$auto_row['name']." - «Банки России»";

require_once APP.HEADFILE;
?>
<script type="text/javascript" src="/files/js/bank_list.js"></script>
<h1>Кредит <?php echo $auto_row['name']?></h1>
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr>
		<td align="left" valign="top" class="banki_main_col">
			<div id="credit_bank">Банк: <a href="<?php echo "/$c_name";?>/banks/<?php echo $auto_row['link'].".html"; ?>"><?php
				echo $auto_row['bank_name'];
			?></a></div>
			<table width="500" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td class="credit_table_item"><strong>Валюта</strong></td>
					<td class="credit_table_item"><strong>Сумма</strong></td>
					<td class="credit_table_item"><strong>Срок</strong>, годы</td>
					<td class="credit_table_item"><strong>Ставка</strong>, %</td>
				</tr><?php
				$cc_res = mysql_query("select * from `credit_currency` where `credit_id` = '$auto_row[auto_id]' and `type` = '2'");
				while($cc_row = mysql_fetch_array($cc_res))
				{
					?><tr>
						<td valign="top" class="credit_table_item"><em><?php
							echo $cc_row['currency'];
						?></em></td>
						<td valign="top" class="credit_table_item">от <?php
							echo getValue($cc_row['sum_low']); ?><br />до <?php echo getValue($cc_row['sum_high']);
						?></td>
						<td valign="top" class="credit_table_item">от <?php
							echo $cc_row['period_low']; ?><br />до <?php echo $cc_row['period_high'];
						?></td>
						<td valign="top" class="credit_table_item">от <?php
							echo $cc_row['rate_low'];?><br />до <?php echo $cc_row['rate_high'];
						?></td>
					</tr><?php
				}
			?></table>
			<div class="credit_second_table">
				<table width="100%" border="0" cellspacing="0" cellpadding="0"><?php
					if ($auto_row['seller'] != "") {
						?><tr>
							<td width="47%" align="left" valign="top" class="credit_second_table_item">Продавец</td>
							<td width="53%" align="left" valign="top" class="credit_second_table_item credit_second_table_item_grey"><?php
							echo $auto_row['seller'];
							?></td>
						</tr><?php
					}
					if ($auto_row['vehicle_type'] != "") {
						?><tr>
							<td align="left" valign="top" class="credit_second_table_item">Вид транспортного средства</td>
							<td align="left" valign="top" class="credit_second_table_item credit_second_table_item_grey"><?php
								echo $auto_row['vehicle_type'];
							?></td>
						</tr><?php
					}
					if ($auto_row['initial_fee'] != "") {
						?><tr>
							<td align="left" valign="top" class="credit_second_table_item">Минимальный первоначальный взнос</td>
							<td align="left" valign="top" class="credit_second_table_item credit_second_table_item_grey"><?php
								echo $auto_row['initial_fee']." %";
							?></td>
						</tr><?php
					}
					if ($auto_row['delivery_commission'] != "") {
						?><tr>
							<td align="left" valign="top" class="credit_second_table_item">Комиссия за выдачу</td>
							<td align="left" valign="top" class="credit_second_table_item credit_second_table_item_grey"><?php
								echo $auto_row['delivery_commission']." %";
							?></td>
						</tr><?php
					}
					if ($auto_row['service_commission'] != "") {
						?><tr>
							<td align="left" valign="top" class="credit_second_table_item">Комиссия за обслуживание</td>
							<td align="left" valign="top" class="credit_second_table_item credit_second_table_item_grey"><?php
								echo $auto_row['service_commission']." %";
							?></td>
						</tr><?php
					}
					?><tr>
						<td align="left" valign="top" class="credit_second_table_item">Возможность досрочного погашения</td>
						<td align="left" valign="top" class="credit_second_table_item credit_second_table_item_grey"><?php
							echo $auto_row['early_repayment'] ? "Да" : "Нет";
						?></td>
					</tr><?php
					if ($auto_row['early_repayment'])
					{
						?><tr>
							<td align="left" valign="top" class="credit_second_table_item">Комиссия за досрочное погашение<br /></td>
							<td align="left" valign="top" class="credit_second_table_item credit_second_table_item_grey"><?php
								echo $auto_row['er_commission']." %";
							?><br /></td>
						</tr><?php
					}
					if ($auto_row['Insurance'] != "") {
						?><tr>
							<td align="left" valign="top" class="credit_second_table_item">Страховка</td>
							<td align="left" valign="top" class="credit_second_table_item credit_second_table_item_grey"><?php
								echo $auto_row['Insurance'];
							?></td>
						</tr><?php
					}
					if ($auto_row['insurance_in_amount'] != "") {
						?><tr>
							<td align="left" valign="top" class="credit_second_table_item">Включение страховки в сумму кредита</td>
							<td align="left" valign="top" class="credit_second_table_item credit_second_table_item_grey"><?php
								echo $auto_row['insurance_in_amount'];
							?></td>
						</tr><?php
					}
					if ($auto_row['documents'] != "") {
						?><tr>
							<td align="left" valign="top">Документы</td>
							<td align="left" valign="top" class=" credit_second_table_item_grey"><?php
								$docs = explode(",",$auto_row['documents']);
								foreach($docs as $item)
									echo $item."<br />";
							?></td>
						</tr><?php
					}
				?></table>
			</div>
		</td>
		<td width="159" align="left" valign="top"><?php
			require_once APP."rating_column.php";
			require_once APP."vacancy_column.php";
		?></td>
	</tr>
</table>
<div class="inside_block">
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr valign='top'>
			<td width="344" class="inside_info"><?php
				require_once APP."bank_list.php";
				require_once APP."currency_rates.php";
			?></td>
			<td width="646"><?php
				echo "<h2>$auto_row[name]</h2>";
				if ($auto_row['info'] != "")
					echo "<p>".getRichText($auto_row['info'])."</p>";
				else
				{
					$info = mysql_fetch_array(mysql_query("select * from `info` where `info_id` = '15' limit 1"));
					$text = getRichText($info['text']);
					echo "<p>$text</p>";
				}
			?></td>
		</tr>
	</table>
</div>
<?php require_once APP.FOOTERFILE; ?>